from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-15 14:11:03.771209
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 15, Apr, 2021
Time: 14:11:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5422
Nobs: 262.000 HQIC: -48.2753
Log likelihood: 3132.75 FPE: 6.61403e-22
AIC: -48.7680 Det(Omega_mle): 4.72126e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.445426 0.124834 3.568 0.000
L1.Burgenland 0.076804 0.061547 1.248 0.212
L1.Kärnten -0.221880 0.053988 -4.110 0.000
L1.Niederösterreich 0.079371 0.134152 0.592 0.554
L1.Oberösterreich 0.215153 0.126857 1.696 0.090
L1.Salzburg 0.269756 0.070130 3.847 0.000
L1.Steiermark 0.126441 0.089575 1.412 0.158
L1.Tirol 0.121516 0.061500 1.976 0.048
L1.Vorarlberg -0.035428 0.056597 -0.626 0.531
L1.Wien -0.065969 0.115422 -0.572 0.568
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486154 0.145642 3.338 0.001
L1.Burgenland -0.003487 0.071805 -0.049 0.961
L1.Kärnten 0.329705 0.062987 5.234 0.000
L1.Niederösterreich 0.076954 0.156512 0.492 0.623
L1.Oberösterreich -0.063648 0.148002 -0.430 0.667
L1.Salzburg 0.222283 0.081819 2.717 0.007
L1.Steiermark 0.109994 0.104506 1.053 0.293
L1.Tirol 0.142970 0.071751 1.993 0.046
L1.Vorarlberg 0.154793 0.066031 2.344 0.019
L1.Wien -0.443203 0.134661 -3.291 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.288208 0.062312 4.625 0.000
L1.Burgenland 0.089306 0.030721 2.907 0.004
L1.Kärnten -0.018541 0.026948 -0.688 0.491
L1.Niederösterreich 0.054858 0.066962 0.819 0.413
L1.Oberösterreich 0.277340 0.063321 4.380 0.000
L1.Salzburg 0.025249 0.035005 0.721 0.471
L1.Steiermark 0.010981 0.044712 0.246 0.806
L1.Tirol 0.073022 0.030698 2.379 0.017
L1.Vorarlberg 0.081597 0.028251 2.888 0.004
L1.Wien 0.122391 0.057613 2.124 0.034
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217944 0.061004 3.573 0.000
L1.Burgenland 0.020502 0.030077 0.682 0.495
L1.Kärnten 0.008825 0.026383 0.334 0.738
L1.Niederösterreich 0.053156 0.065557 0.811 0.417
L1.Oberösterreich 0.401409 0.061992 6.475 0.000
L1.Salzburg 0.082617 0.034271 2.411 0.016
L1.Steiermark 0.129102 0.043773 2.949 0.003
L1.Tirol 0.050264 0.030054 1.672 0.094
L1.Vorarlberg 0.084307 0.027658 3.048 0.002
L1.Wien -0.047893 0.056404 -0.849 0.396
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.500983 0.119201 4.203 0.000
L1.Burgenland 0.092318 0.058769 1.571 0.116
L1.Kärnten 0.011762 0.051552 0.228 0.820
L1.Niederösterreich 0.005033 0.128098 0.039 0.969
L1.Oberösterreich 0.129447 0.121132 1.069 0.285
L1.Salzburg 0.058491 0.066965 0.873 0.382
L1.Steiermark 0.067468 0.085533 0.789 0.430
L1.Tirol 0.212812 0.058724 3.624 0.000
L1.Vorarlberg 0.031694 0.054043 0.586 0.558
L1.Wien -0.102406 0.110213 -0.929 0.353
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189098 0.094206 2.007 0.045
L1.Burgenland -0.012746 0.046446 -0.274 0.784
L1.Kärnten -0.008389 0.040742 -0.206 0.837
L1.Niederösterreich -0.004753 0.101238 -0.047 0.963
L1.Oberösterreich 0.399762 0.095733 4.176 0.000
L1.Salzburg 0.016602 0.052923 0.314 0.754
L1.Steiermark -0.019243 0.067598 -0.285 0.776
L1.Tirol 0.159069 0.046411 3.427 0.001
L1.Vorarlberg 0.053477 0.042711 1.252 0.211
L1.Wien 0.232206 0.087103 2.666 0.008
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.238580 0.114747 2.079 0.038
L1.Burgenland 0.018190 0.056573 0.322 0.748
L1.Kärnten -0.069403 0.049626 -1.399 0.162
L1.Niederösterreich -0.073780 0.123312 -0.598 0.550
L1.Oberösterreich 0.019919 0.116606 0.171 0.864
L1.Salzburg 0.083118 0.064463 1.289 0.197
L1.Steiermark 0.336633 0.082337 4.088 0.000
L1.Tirol 0.462036 0.056530 8.173 0.000
L1.Vorarlberg 0.147778 0.052024 2.841 0.005
L1.Wien -0.158722 0.106095 -1.496 0.135
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183628 0.136962 1.341 0.180
L1.Burgenland 0.039745 0.067526 0.589 0.556
L1.Kärnten -0.074891 0.059233 -1.264 0.206
L1.Niederösterreich 0.131855 0.147185 0.896 0.370
L1.Oberösterreich 0.017971 0.139181 0.129 0.897
L1.Salzburg 0.199978 0.076943 2.599 0.009
L1.Steiermark 0.117253 0.098277 1.193 0.233
L1.Tirol 0.057844 0.067474 0.857 0.391
L1.Vorarlberg 0.103365 0.062095 1.665 0.096
L1.Wien 0.229638 0.126635 1.813 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.561990 0.074317 7.562 0.000
L1.Burgenland -0.025921 0.036640 -0.707 0.479
L1.Kärnten -0.023170 0.032141 -0.721 0.471
L1.Niederösterreich 0.052322 0.079864 0.655 0.512
L1.Oberösterreich 0.310324 0.075521 4.109 0.000
L1.Salzburg 0.021441 0.041750 0.514 0.608
L1.Steiermark -0.035063 0.053326 -0.658 0.511
L1.Tirol 0.085630 0.036612 2.339 0.019
L1.Vorarlberg 0.111050 0.033694 3.296 0.001
L1.Wien -0.052335 0.068713 -0.762 0.446
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.144998 0.077532 0.161763 0.221336 0.079135 0.082262 0.013024 0.152050
Kärnten 0.144998 1.000000 0.035893 0.202693 0.177688 -0.061615 0.164412 0.026330 0.302259
Niederösterreich 0.077532 0.035893 1.000000 0.236035 0.075488 0.322966 0.141146 0.027361 0.292178
Oberösterreich 0.161763 0.202693 0.236035 1.000000 0.299672 0.268217 0.089290 0.059686 0.130607
Salzburg 0.221336 0.177688 0.075488 0.299672 1.000000 0.154373 0.053042 0.087978 0.009306
Steiermark 0.079135 -0.061615 0.322966 0.268217 0.154373 1.000000 0.103768 0.095977 -0.106997
Tirol 0.082262 0.164412 0.141146 0.089290 0.053042 0.103768 1.000000 0.161548 0.147147
Vorarlberg 0.013024 0.026330 0.027361 0.059686 0.087978 0.095977 0.161548 1.000000 -0.009717
Wien 0.152050 0.302259 0.292178 0.130607 0.009306 -0.106997 0.147147 -0.009717 1.000000